﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PerformanceCompareTest.Helpers
{
    internal static class TimeHelper
    {
        public static bool IsInRangeWithDuration(double startTime, double duration, double value)
        {
            return IsInRangeWithEndTime(startTime, startTime + duration, value);
        }

        public static bool IsInRangeWithEndTime(double startTime, double endTime, double value)
        {
            if (startTime > value) return false;
            if (endTime < value) return false;
            return true;
        }

        ///<summary>当前时间是否在指定区域内。</summary>
        public static bool IsInRange(double time1, double time2, double value)
        {
            if (time1 < time2)
            {
                return IsInRangeWithEndTime(time1, time2, value);
            }
            else
            {
                return IsInRangeWithEndTime(time2, time1, value);
            }
        }

        ///<summary>获得当前时间在指定区域内的进度百分比。</summary>
        public static double GetProgressWithDuration(double startTime, double duration, double value)
        {
            return (value - startTime) / duration;
        }

        public static double GetProgressWithEndTime(double startTime, double endTime, double value)
        {
            return (value - startTime) / (endTime - startTime);
        }

    }
}
